package com.batis.source.io;

import org.apache.ibatis.io.ClassLoaderWrapper;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

/**
 * 读取配置文件
 * @author isam2016
 * @create 2021-08-25 4:47 PM
 */
public class MYResources {

    private static MYClassLoaderWrapper classLoaderWrapper = new MYClassLoaderWrapper();

    MYResources() {

    }

    public static Reader getResourceAsReader(String resource) throws IOException {
        Reader reader = new InputStreamReader(getResourceAsStream(resource));
        return reader;
    }

    public static InputStream getResourceAsStream(String resource) throws IOException{
        InputStream in = classLoaderWrapper.getResourceAsStream(resource);
        if (in == null) throw new IOException("Could not find resource " + resource);
        return in;
    }
}
